package utilities;

import java.util.HashSet;

//returns a unique Integer value when newID() called.
//Support up to 4,294,967,296 objects.
public class IDGenerator {
	
	
	private static IDGenerator idGen = new IDGenerator();
	private HashSet<Key> keys = new HashSet<Key>();
	int i;//, j, k, m;
		
	private IDGenerator()
	{
		i = Integer.MIN_VALUE;
		//i = 0;
//		j = 0;
//		k = 0;
//		m = 0;
	}
	
	public static IDGenerator getInstance()
	{
		return idGen;
	}
	
	public Key newID()
	{
		i++;
		
//		i++;
//		j += (int)Math.floor(i/128);
//		k += (int)Math.floor(j/128);
//		m += (int)Math.floor(k/128);
//		
//		if (i==128)
//			i = 0;
//		
//		if (j==128)
//			j = 0;
//		
//		if (k==128)
//			k = 0;
//		
//		char a = (char)i;
//		char b = (char)j;
//		char c = (char)k;
//		char d = (char)m;
//		
//		String temp = "" + a + b + c + d;		
		
		//Key key = new Key(temp);
		Key key = new Key(i);
		
		keys.add(key);
		
		return key;		
	}	
	
	public boolean checkID(Key key)
	{
		if (keys.contains(key))
			return true;
		else
			return false;
	}
	
	
	
	

}

	
